<template>
  <div :class="['show-hall', $ua.isFromPc() ? 'z-web' : 'z-phone']">
    <img :src="artData?.title_page" alt="" class="banner">
    <div class="introduction-title">
      {{ artData?.name || '展览介绍' }}
    </div>
    <div class="tab">
      <div :class="['introduction', 'all-center', active == 0 ? 'active-introduction' : '']" @click="jump(0)">
        展览介绍
      </div>
      <div :class="['open', 'all-center', active == 1 ? 'active-open' : '']" @click="jump(1)">
        展览活动
      </div>
      <div :class="['exhibit', 'all-center', active == 2 ? 'active-exhibit' : '']" @click="jump(2)">
        展厅展览
      </div>
      <div :class="['online', 'all-center', active == 3 ? 'active-online' : '']" @click="jump(3)">
        线上展览
      </div>
    </div>
    <introduction :desc="artData?.introduction" v-show="active == 0" />
    <open v-show="active == 1" />
    <exhibit v-show="active == 2" />
    <div class="work-list" v-if="work_list.length > 0 && active == 3">
      <div class="content" v-for="(item, i) in work_list" :key="i">
        <div class="video-content" v-if="item.type == 1">
          <client-only>
            <video-player
              :ref="'videoPlayer' + item.data_id"
              :options="PlayerArry[i]"
              @ended="onPlayerEnded($event)"
              @play="onPlayerPlay($event, item.data_id)"
              :playsinline="true"
              class="video-player vjs-custom-skin" >
            </video-player>
          </client-only>
          <div class="name" :title="item.name">
            {{ item.name }}
          </div>
          <div class="art_name">
            {{ item.art_name }}
            <div class="collect">
              <img src="@/static/img/editPersonalHome/zhenyan.png" alt="">
              {{ item.view_times }}
            </div>
          </div>
        </div>
        <div v-else class="work-content" @click="lookBig(item.opus_id[0]?.id)">
          <img :src="getBigImg(item.opus_id[0]?.id)" alt="">
          <div class="name" :title="item.name">
            {{ item.name }}
          </div>
          <div class="art_name">
            {{ item.art_name }}
            <div class="collect">
              <img src="@/static/img/editPersonalHome/zhenyan.png" alt="">
              {{ item.view_times }}
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="see-more">
      <div class="line"></div>
      <div @click="go" class="text">查看更多<img src="@/static/img/home/arrow.png" alt=""></div>
    </div>
  </div>
</template>

<script>
import open from './components/open.vue'
import exhibit from './components/exhibit.vue'
import { getBigImg } from '../../utils/downloadFile'
import introduction from './components/introduction.vue'
export default {
  scrollToTop: true,
  name: 'showHall',
  components: {
    introduction,
    open,
    exhibit
  },
  data() {
    return {
      artData: {},
      tabList: [
        '展览介绍',
        '作品展示'
      ],
      active_id: '',
      active: 0,
      work_list: [],
      VideoIndex: 0,
      VideoArry: [],
      PlayerArry: [],
      currentPlayer: null,
      playerOptions: {//video-player组件播放视频所需的参数，此参数作为模板用于复制
        controls: true, // 是否显示控制栏
        // playbackRates: [ 0.5, 1.0, 1.5, 2.0 ], //可选择的播放速度
        autoplay: false, //如果true,浏览器准备好时开始回放。
        muted: true, // 默认情况下将会消除任何音频。
        loop: false, // 视频一结束就重新开始。
        preload: 'auto', // 建议浏览器在<video>加载元素后是否应该开始下载视频数据。auto浏览器选择最佳行为,立即开始加载视频（如果浏览器支持）
        language: 'zh-CN',
        aspectRatio: '16:9', // 将播放器置于流畅模式，并在计算播放器的动态大小时使用该值。值应该代表一个比例 - 用冒号分隔的两个数字（例如"16:9"或"4:3"）
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        sources: [
          { type : "",src : 'http://221.12.172.138:908/Upload/2021-01-11-11-27-56-1306734.mp4'} //url地址
        ],
        poster: "", //你的封面地址
        // width: document.documentElement.clientWidth,//视频画面宽度
        notSupportedMessage: '此视频暂无法播放，请稍后再试', //允许覆盖Video.js无法播放媒体源时显示的默认信息。
        controlBar: {
          timeDivider: false,//当前时间和持续时间的分隔符
          durationDisplay: false,//显示持续时间
          remainingTimeDisplay: false,//是否显示剩余时间功能
          fullscreenToggle: true,  //全屏按钮
          progressControl: false,
          volumePanel: true
        },
        playtimes: 0,//视频播放起点
        preload: "auto"
      },
      activeVideoId: null
    }
  },
  mounted() {
    this.getArtHall(this.$route.query.data_id)
    this.getArtWork(this.$route.query.data_id)
  },
  methods: {
    getBigImg,
    getArtWork(stadiums_id) {
      const params = {
        stadiums_id
      }
      this.$api.getArtWork(params).then(res => {
        this.work_list = Array.isArray(res.result.item_list) ? res.result.item_list.slice(0, 8) : []
        this.work_list.forEach((v, i) => {
          if (v.type == 1) {
            let op = JSON.parse(JSON.stringify(this.playerOptions));
            op.sources = [{ type : "video/mp4" ,src: v.video_url }];
            op.poster = v.title_page || ''
            this.PlayerArry.push(op);
          } else {
            this.PlayerArry.push({})
          }
        })
      })
    },
    // 查看大图
    lookBig(id) {
      console.log(id)
      if (process.browser && id) {
        let {
          BasicDraw,
          BigImageShow
        } = require("../../utils/main.js")
        let basicDraw = new BasicDraw(); // 创建基础渲染类
        basicDraw.start(); // 开始渲染
        new BigImageShow().showBigImg(id)

        document.getElementById('bigIamgeClose').addEventListener('click', (e) => {
          basicDraw.dispose()
          e.stopPropagation()
        })
      }
    },
    go() {
      this.$router.push({
        path: '/artShop/showHall/showHallDesc',
        query: { data_id: this.$route.query.data_id, type: 'art' }
      })
    },
    onPlayerEnded(obj){//播放完成后进行回调
      // let oldValue = this.VideoIndex;
      this.VideoIndex = this.VideoIndex < (this.VideoArry.length - 1) ? this.VideoIndex + 1 : 0
      // this.VideoChange(oldValue, this.VideoIndex);
    },
    onPlayerPlay(player, data_id) {
      this.work_list.forEach(item => {
        if (item.video_url) {
          this.$refs['videoPlayer' + item.data_id].forEach(ele => {
            if (item.data_id !== data_id) {
              ele.player.pause()
            }
          })
        }
      })
    },
    jump(value) {
      this.active = value
    },
    getArtHall(data_id) {
      const params = {
        data_id
      }
      this.$api.getArtHall(params).then(res => {
        this.artData = res.result
      })
    }
  }
}
</script>

<style lang="less" scoped>
.show-hall {
  &.z-web {
    position: relative;
    .banner {
      width: 100%;
      height: 952px;
      object-fit: cover;
    }

    .introduction-title {
      font-size: 44px;
      font-weight: 600;
      color: #000;
      padding: 30px 0;
      text-align: center;
      background-color: #fff;
    }


    .tab {
      text-align: center;
      padding: 60px 0 20px;
      background: #fff;

      .introduction,
      .exhibit,
      .online,
      .open {
        width: 200px;
        height: 61px;
        background: #FFF;
        border: 1px solid #E4E4E4;
        cursor: pointer;
        font-size: 22px;
      }

      .active-open,
      .active-online {
        border: 1px solid #333;
        font-weight: 800;
      }

      .active-introduction {
        border: 1px solid #333;
        font-weight: 800;
      }

      .active-exhibit {
        border: 1px solid #333;
        font-weight: 800;
      }

      .introduction,
      .exhibit,
      .open {
        margin-right: 35px;
      }
    }

    .work-list {
      background-color: #fff;
      padding: 0 276px 50px;
      display: grid;
      justify-content: space-between;
      grid-template-columns: repeat(auto-fill, 320px);
      grid-gap: 10px;

      .content {
        // width: 320px;
        // height: 240px;
        margin-bottom: 30px;

        .work-content {
          height: 100%;
          width: 100%;

          img {
            width: 320px;
            height: 240px;
            object-fit: cover;
          }
        }

        .work-content,
        .video-content {
          font-size: 16px;
          color: #999;
          font-weight: bold;
          cursor: pointer;

          .el-image {
            width: 100%;
            height: 100%;
          }

          .name {
            width: 320px;
            color: #000;
            font-weight: 600;
            margin: 6px 0;
            overflow: hidden; //超出的文本隐藏
            text-overflow: ellipsis; //溢出用省略号显示
            white-space: nowrap;
          }
          .art_name,
          .desc {
            color: #999;
            margin-bottom: 10px;
          }
          .collect {
            float: right;
            img {
              // width: 30px;
              width: 18px;
              height: 18px;
              position: relative;
              top: -3px;
              margin-right: 5px;
            }
          }

          .video-player {
            width: 320px;
            height: 240px;
          }

          ::v-deep(.vjs-custom-skin > .video-js) {
            height: 100%;
          }
        }
      }
    }

    .see-more {
      position: absolute;
      right: 276px;
      bottom: 0;
    }
  }

  &.z-phone {
    margin-top: pxtorem(88) !important;
    padding-bottom: pxtorem(50);

    .banner {
      width: 100%;
      height: pxtorem(388);
      object-fit: cover;
    }

    .introduction-title {
      font-size: pxtorem(24);
      color: #000;
      font-weight: 600;
      margin: pxtorem(25) 0;
      text-align: center;
    }

    .tab {
      text-align: center;

      .introduction,
      .open {
        width: pxtorem(110);
        display: inline-block;
        font-size: pxtorem(24);
        font-weight: bold;
        color: #898989;
        flex: 25%;
        text-align: center;
        margin-bottom: pxtorem(42);
        margin-right: pxtorem(42);

        &:last-child {
          margin: 0;
        }

        &.active-introduction,
        &.active-open {
          color: #000;
          position: relative;
        }

        &.active-introduction::after,
        &.active-open::after {
          content: '';
          width: pxtorem(100);
          height: pxtorem(4);
          background-color: #000;
          position: absolute;
          bottom: pxtorem(-6);
          left: pxtorem(5);
        }
      }
    }

    .work-list {
      padding: pxtorem(50) pxtorem(25);
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;

      .content {
        margin-bottom: pxtorem(25);
        .video-content {
          // width: pxtorem(340);
          // height: pxtorem(245);
          .video-player {
            width: pxtorem(340);
            height: pxtorem(245);
          }

          ::v-deep(.vjs-custom-skin > .video-js) {
            height: 100%;
          }

          .collect {
            // width: pxtorem(30);
            float: right;
            img {
              width: pxtorem(30);
              height: pxtorem(30);
            }
          }
        }

        .work-content {
          img {
            width: pxtorem(340);
            height: pxtorem(245);
            object-fit: cover;
          }

          .collect {
            // width: pxtorem(30);
            float: right;
            img {
              width: pxtorem(30);
              height: pxtorem(30);
            }
          }

          // .collect {
          //   float: right;
          //   img {
          //     // width: 30px;
          //     width: 18px;
          //     height: 18px;
          //     position: relative;
          //     top: -3px;
          //     margin-right: 5px;
          //   }
          // }
        }
      }
    }

    .see-more {
      width: pxtorem(100);
      margin: 0;
      margin-left: pxtorem(25);

      img {
        width: pxtorem(50);
      }
    }
  }
}
</style>